//
//  SetPasswordViewController.m
//  ios-test
//
//  Created by Apple -11 on 15/10/21.
//  Copyright (c) 2015年 Apple -11. All rights reserved.
//

#import "SetPasswordViewController.h"
#import "Tools.h"
#import "goodsViewController.h"
#import "ICSDrawerController.h"
#import "MenuViewController.h"
#import "PassworldViewController.h"
@interface SetPasswordViewController ()

@end

@implementation SetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    label.text=@"Enter password";
    i=1;
    passwordUser=[NSUserDefaults standardUserDefaults];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)toSave:(id)sender{
    if ([Tools CheckInput4:passwordText.text]) {
        if (i==1) {
            //[[passwordUser objectForKey:@"pass"]isEqualToString:@""]||[passwordUser objectForKey:@"pass"]
            label.text=@"Sure password";
            NSString *password=passwordText.text;
            [passwordUser setObject:password forKey:@"pass"];
            passwordText.text=NULL;
            i++;
            
            }else{
                [self check];
            }
        
    }else{
        UIAlertView *alter=nil;
        alter=[[UIAlertView alloc]initWithTitle:@"警告！！！！" message:@"请输入四位纯数字" delegate:nil cancelButtonTitle:@"close" otherButtonTitles:nil, nil];
        [alter show];
        passwordText.text=NULL;
    }
}
-(void)check{
    if ([[passwordUser objectForKey:@"pass"]isEqualToString:passwordText.text]) {
    
        [self dismissViewControllerAnimated:YES completion:nil];
            if ([self.delegate respondsToSelector:@selector(dismissVC)]) {
                [self.delegate dismissVC];
            }
       

//        MenuViewController *colorsVC = [[MenuViewController alloc] init];
//        goodsViewController *good=[[goodsViewController alloc]init];
//        ICSDrawerController *drawer = [[ICSDrawerController alloc] initWithLeftViewController:colorsVC
//                                                                                 centerViewController:good];
//        [self presentViewController:drawer animated:YES completion:nil];
        
    }else{
        UIAlertView *alter=nil;
        alter=[[UIAlertView alloc]initWithTitle:@"警告！！！！" message:@"2次密码不相同" delegate:nil cancelButtonTitle:@"close" otherButtonTitles:nil, nil];
        [alter show];
        passwordText.text=NULL;
    }
 
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
